package model;

import java.util.Iterator;
import java.util.Vector;

public class cage {
	private int targetNumber, sizeOfCage;
	private String operator;
	public Vector<block> listOfCells = new Vector();
	public Iterator<block> itBlock;
	public cage(String[] cageAttributes, int arraySize) throws NullPointerException{
		targetNumber = Integer.parseInt(cageAttributes[0]);
		operator = cageAttributes[1];
		sizeOfCage = Integer.parseInt(cageAttributes[2]);
		for (int i=3;i<arraySize;i++){
			listOfCells.add(new block(cageAttributes[i]));
		}
		itBlock = listOfCells.iterator();
	}
	public int returnTargetNumber() {
		return targetNumber;
	}
	public int returnsizeOfCage() {
		return sizeOfCage;
	}
	public String returnOperator() {
		return operator;
	}
	public void setCellValueWhenCageSizeIsOne() {
		listOfCells.elementAt(0).setCellValue(targetNumber);
	}
	public void setCellValue(int cellValue1,int cellValue2) {
		listOfCells.elementAt(0).setCellValue(cellValue1);
		listOfCells.elementAt(1).setCellValue(cellValue2);
	}
	public boolean checkCellValueInRowColumn(int tempRow,int tempColumn, int newCellValue) {
		int found=0;
		for(int i=0;i<listOfCells.size();i++){
			if ((listOfCells.elementAt(i).returnBlockNumber()==newCellValue) && ((tempRow==listOfCells.elementAt(i).returnRowNumber()) | tempColumn==listOfCells.elementAt(i).returnColumnNumber())){
				return true;//number already exists in that row and column
				
				
			}
			
		}
		return false;
	}
	public int returnRowNumberOfCell1(){
		return listOfCells.elementAt(0).returnRowNumber();
	}
	public int returnRowNumberOfCell2() {
		return listOfCells.elementAt(1).returnRowNumber();
	}
	public int returnColumnNumberOfCell1(){
		return listOfCells.elementAt(0).returnColumnNumber();
	}
	public int returnColumnNumberOfCell2() {
		return listOfCells.elementAt(1).returnColumnNumber();
	}
	public void setRulesSatifiedForCells(){
		for(int i=0;i<listOfCells.size();i++){
			listOfCells.elementAt(i).setSatisfiedToTrue();
		}
	}
	public String returnCellInfo(){
		String info="";
		for(int i=0;i<listOfCells.size();i++)
			info=info+listOfCells.elementAt(i).returnBlockNumber()+"  "+listOfCells.elementAt(i).returnColumn()+listOfCells.elementAt(i).returnRow()+"\n";
		return info;
	}
	
		
	
	}